<%@page import="Interact.Interface"%>
<%@page import="Test.Question"%>
<%@page import="DBModule.TestPaperManager"%>
<%@page import="Test.TestPaper"%>
<%@page import="Servlet.Alert"%>
<%@page import="User.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>批阅</title>
<link rel="stylesheet" href="css/default.css" type="text/css" />
</head>
<body>
<form method="post" action="TestServlet?method=correct">
<%
	User teacher = (User)session.getAttribute("user");
	if (teacher == null || teacher.getType() != User.TEACHER){
		Alert.toAlert(response, request, "用户未登陆，或不是教师");
		return;
	}
	
	int pid;
	
	try{pid = Integer.parseInt(request.getParameter("paperID"));}
	catch (Exception e){
		Alert.toAlert(response, request, "未选择试卷");
		return;
	}
	
	try{
		TestPaper paper = TestPaperManager.loadPaper(pid);
		session.setAttribute("paper", paper);
		paper.setMode(Question.CORRECT_MODE);
		paper.display(new Interface(out));
	}
	catch (Exception e){
		e.printStackTrace();
		String msg = e.getMessage();
		Alert.toAlert(response, request, msg == null ? "未知的内部错误" : msg);
		return;
	}
%>
<input type="hidden" name="state" value="<%=TestPaper.CORRECTED%>" />
<script type="text/javascript">
	function foo1(){
		document.getElementsByName("state")[0].value = <%=TestPaper.CORRECTED%>;
	}
	function foo2(){
		document.getElementsByName("state")[0].value = <%=TestPaper.UNCORRECT%>;
	}
</script>
<input type="submit" value="批改完毕" onclick="foo1()"><br/>
<input type="submit" value="暂时保存" onclick="foo2()"><br/>
</form>
</body>
</html>